package com.misty.chain_pattern.client;

public abstract class Handler {
    public static final int FATHER_LEVEL_REQUEST = 1;
    public static final int HUSBAND_LEVEL_REQUEST = 2;
    public static final int SON_LEVEL_REQUEST = 3;

    //能处理的级别
    private int level = 0;

    //责任链传递，下一个责任人是谁
    private Handler nextHandler;

    //每个类都要说明一下只能处理那些请求;
    public Handler(int level) {
        this.level = level;
    }

    public final void handleMessage(IWomen women) {
        if (women.getType() == this.level) {
            this.response(women);
        } else {
            if (this.nextHandler != null) {
                nextHandler.handleMessage(women);
            } else {
                System.out.println("没有下一个处理人了,不用处理了");
            }
        }
    }

    public void setNextHandler(Handler handler) {
        this.nextHandler = handler;
    }

    protected abstract void response(IWomen women);
}
